<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body class="body">

<form class="layui-form" action="" method="post" id="addform">
  <div class="layui-form-item">
    <label class="layui-form-label">角色</label>
    <div class="layui-input-inline">
      <input type="hidden" name="names">
      <input type="text" class="layui-input" name="names" placeholder="请输入角色名，多个角色间以逗号分隔" onkeyup="value=value.replace(/，/ig,',')">
      </select>
    </div>
  </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" lay-verify="required" name="content" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">物品</label>
        <div class="layui-input-inline">
            <input type="text" id="sfsfsdfsd" name="goodssearch" placeholder="请输入物品信息搜索物品" class="layui-input search-w" style="width:180px;float:left"><!-- <input type="number" name="num" class="layui-input" lay-verify="required" min="1" placeholder="数量" style="margin-left:10px;width:60px;float:left"><i class="layui-icon layui-icon-add-1" id="addgoods" style="padding:9px;line-height:20px;display:block;font-size: 20px;margin-left:10px;"></i>   -->
        </div>
        <div class="layui-input-inline"></div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">物品信息</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入物品信息" lay-verify="required" name="goods" readonly="readonly" class="layui-textarea" style="min-height:55px"></textarea>
        </div>
    </div>
      <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" class="layui-input">
        </div>
    </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
          
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__ADMIN__/js/comm.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'admin','autocomplete'], function() {
      var form = layui.form,
        layer = layui.layer,
        $ = layui.$, //重点处
        autocomplete = layui.autocomplete,
        admin = layui.admin;


      //自定义验证规则
      form.verify({
        name: function(value) {
          if (value.length < 2) {
            return '标题至少得2个字符啊';
          }
        }
      });
/*
      $('#addgoods').click(function(event) {
        var oval = $("textarea[name='goods']").val();
        var goods = $("input[name='goodssearch']").val();
        var num = $("input[name='num']").val();
        if(goods.length<1 || num<1){
            layer.alert('物品，或数量必须存在');  
            return;        
        }
        if(oval.length>0){
          nval = $("textarea[name='goods']").val(oval+','+goods+'|'+num);
        }else{
          nval = $("textarea[name='goods']").val(goods+'|'+num);
        }
      });
*/
//iframe层-父子操作
$('.search-w').click(function(){
  layer.open({
    type: 2,
    area: ['700px', '450px'],
    fixed: false, //不固定
    maxmin: true,
    content: '{:url('showwelfare')}'
  });

});





/*
        autocomplete.init({
            elem:"input[name=goodssearch]",
            textLength:2,//触发长度
            delay:200,//触发延迟
            callback:{
                data:function(val,render){
                  console.log(val);
                  $.post("{:url('ajaxkeywords')}", {'keywords': val}, function(data) {
                    if(data.code == 1){
                      render(data.data);
                      //console.log(data.data);
                    }
                  });
                  //var data = "{:url('ajaxkeywords')}?keywords="+ val;
                    // var data = [
                    //     {title:"1231",value:"1231"+Math.random()},
                    //     {title:"1232",value:"1232"},
                    //     {title:"1233",value:"1233"},
                    //     {title:"1234",value:"1234"}
                    // ];
                    //render(data);
                },
                selected:function(data){
                    console.log(JSON.stringify(data));
                },
                close:function(){

                }
            }
        });
*/






      // function handlerVals(arr) {
      //   var str = '';
      //   $.each(arr, function(i, obj) {
      //       str += obj.name +',';
      //   });
      //   str = str.substr(0, (str.length - 1));
      //   $("input[name='goods']").val(str);
      //   console.log(str);
      // }

//https://www.cnblogs.com/jingliwufadaodai/p/5756018.html
        // formSelects.render({
        //   name: 'select17',//xm-select的值
        //   type: 3,//等效xm-select-type, 选择样式
        //   max: 1,//最大多选值
        //   init: [],//初始化选择值, 优先级高
        //   on: function(data, arr){ //监听数据变化
        //     //console.log(data);//layui.form.on的data
        //     console.log(arr);//已选择数据的数组
        //     handlerVals(arr);
        //   },
        //   maxTips: function(arr, val, max){
        //     layer.msg(`选择的数据: ${val.name}, 已超出最大选值: ${max}`, {icon: 2});  
        //     console.table(arr);//已选择数据
        //     console.log(val);//{name: '北京', val: '1'}
        //     console.log(max);//5
        //   },
        //   data: {
        //     arr: [
        //       {content: '全选', value: 1, sel: true, dis: true},
        //       {content: '全不选', value: 2, sel: false, dis: false},
        //       {content: '反选', value: 3, sel: false, dis: false},
        //       {content: '还有啥', value: 4, sel: false, dis: false},
        //       {content: '没了吧', value: 5, sel: false, dis: false},
        //     ],
        //     name: 'content',//定义name的key, 默认name
        //     val: 'value',//定义val的key, 默认val
        //     selected: 'sel',//定义selected的key, 默认selected
        //     disabled: 'dis',//定义disabled的key, 默认disabled
        //   }
        // });
        //handlerVals(formSelects.value('select'));


      //创建一个编辑器

      //监听指定开关
      // form.on('submit(demo1)', function(data) {
      //   $.post('{:url('add')}', $('#addform').serialize(),
      //     function(data) {
      //       if (data.code == 1) {
      //         layer.alert(data.msg, {
      //           skin: 'layui-layer-molv' //样式类名
      //             ,
      //           closeBtn: 0
      //         }, function() {
      //           location.href = data.url;
      //         });
      //       } else {
      //         layer.msg(data.msg);
      //       }
      //     });
      //   return false;
      // });

        form.on('submit(demo1)', function(data){
            admin.action("{:url('admin/Welfare/add')}",$("#addform").serialize());
            return false;
        });

    });
</script>

</body>
</html>